from rest_framework import serializers
from orders.models import OrderInfo, OrderGoods
from goods.models import SKU

class OrderInfoModelSerializer(serializers.ModelSerializer):
    # serializers.DateTimeField(format='%Y/%m/%d', input_formats='%Y-%m-%d')
    class Meta:
        model = OrderInfo
        fields = [
            'order_id',
            'create_time'
        ]
        extra_kwargs = {
            'create_time': {'format': '%Y/%m/%d'}
        }

class SKUSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = [
            'name',
            'default_image'
        ]

class OrderGoodsModelSerializer(serializers.ModelSerializer):
    sku = SKUSimpleSerializer()
    class Meta:
        model = OrderGoods
        fields = [
            'count',
            'price',
            'sku'
        ]


class OrderDetailModelSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField()
    skus = OrderGoodsModelSerializer(many=True)

    class Meta:
        model = OrderInfo
        fields = '__all__'